<template>
  <div>
     <Row>
        <Date-picker v-model="startMonth" placeholder="开始月" format="yyyy-MM"></Date-picker>
        <Date-picker v-model="endMonth" placeholder="结束月" format="yyyy-MM"></Date-picker>
        <Button type="primary" @click="onSearch">查询</Button>
    </Row>
    <Table :border="true" :stripe="true" :show-header="true" :data="tableData" :columns="tableColumns"></Table>
    <Page class="bottom-page" :total="totalPage" :current="crtPage" :page-size="pageSize" show-total show-elevator @on-change="onChange"></Page>
  </div>
</template>
<script>

import {getMonthTotalAnalys} from '@/api/recharge.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      tableData: [],
      startMonth: '',
      endMonth: '',
      crtPage: 1,
      totalPage: 0,
      pageSize: 10
    }
  },
  created () {
    this.endMonth = new Date()
    let sY = this.endMonth.getFullYear()
    let sM = this.endMonth.getMonth() + 1
    if (sM < 7) {
      sM = sM + 12 - 7
      sY = sY - 1
    } else {
      sM = sM - 7
    }
    this.startMonth = new Date(sY + '-' + sM)

    console.log('this.startMonth:', this.startMonth)
    this.onSearch()
  },
  methods: {
    onSearch () {
      let sSendMonth = 0
      let eSendMonth = 0
      if (this.startMonth !== '' && this.endMonth !== '') {
        let sMonth = new Date(this.startMonth)
        let eMonth = new Date(this.endMonth)
        // sSendMonth = '' + sMonth.getFullYear() + ((sMonth.getMonth() + 1) < 10 ? '0' + (sMonth.getMonth() + 1) : (sMonth.getMonth() + 1))
        // eSendMonth = '' + eMonth.getFullYear() + ((eMonth.getMonth() + 1) < 10 ? '0' + (eMonth.getMonth() + 1) : (eMonth.getMonth() + 1))
        // sSendMonth = parseInt(sSendMonth)
        // eSendMonth = parseInt(eSendMonth)
        sSendMonth = sMonth.getTime()
        eSendMonth = eMonth.getTime()
      }

      console.log('sSendMonth:', sSendMonth, ',eSendMonth:', eSendMonth)
      getMonthTotalAnalys(this.crtPage, this.pageSize, sSendMonth, eSendMonth).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RechargeAnalysVO = getVO('RechargeAnalysVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RechargeAnalysVO.decode(pv.data[i])
          this.tableData.push(vo)
        }
        this.totalPage = pv.intValues[1]
        console.log(this.tableData)
      })
    },
    onChange (item) {
      console.log(item)
      this.crtPage = item
      this.onSearch()
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '时间',
          key: 'time',
          align: 'center'
        },
        {
          title: '充值量',
          key: 'amount',
          align: 'center'
        },
        {
          title: '获得金币',
          key: 'points',
          align: 'center'
        },
        {
          title: '充值玩家数',
          key: 'userNum',
          align: 'center'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.log-str{
  font-size: 14px;
  margin-bottom: 2px;
}
.content{
  min-height: 460px;
}
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
</style>
